﻿using Avalonia;
using Avalonia.Controls.ApplicationLifetimes;
using Avalonia.Data.Core.Plugins;
using Avalonia.Markup.Xaml;
using System.Runtime.InteropServices;
using WeChat.Extensions;
using WeChat.ViewModels;
using WeChat.Views;

namespace WeChat;

public partial class App : Application
{
    public App()
    {
        DataContext = new ApplicationViewModel();
    }
    
    public override void Initialize()
    {
        AvaloniaXamlLoader.Load(this);
        TemplatedControlExtension.Init();
    }

    public override void OnFrameworkInitializationCompleted()
    {
        // Line below is needed to remove Avalonia data validation.
        // Without this line you will get duplicate validations from both Avalonia and CT
        BindingPlugins.DataValidators.RemoveAt(0);

        if (ApplicationLifetime is IClassicDesktopStyleApplicationLifetime desktop)
        {
            desktop.MainWindow = new MainWindow();

            if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
            {
                // desktop.MainWindow.Classes.Clear();
                // desktop.MainWindow.Classes.Add("Windows");
            }
            else if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
            {
                desktop.MainWindow.Classes.Clear();
                desktop.MainWindow.Classes.Add("Mac");
            }
        }
        else if (ApplicationLifetime is ISingleViewApplicationLifetime singleViewPlatform)
        {
            singleViewPlatform.MainView = new MainView();
        }

        base.OnFrameworkInitializationCompleted();
    }
}
